<template>
  <div class="wrapper">
    <div class="list">
      <div class="item" v-for="(item, index) in list" :key="index">
        <div class="time">时间: {{ item.create_time }}</div>
        <div class="sum">进货人ID: {{ item.received_id }}</div>
        <div class="user">数量: {{ item.sum }}</div>
        <div class="user" v-if="+item.status !== 0">{{ item.status | statusText }}</div>
        <div class="ops" v-else>
          <div>
            <cube-button inline primary small @click="check(item)">审核通过</cube-button>
          </div>
          <div>
            <cube-button inline @click="reject(item)">驳回/拒绝</cube-button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import api from '@/api'
import base64 from '@/util/base64'
export default {
  data() {
    return {
      list: []
    }
  },
  filters: {
    statusText(v) {
      let str = ''
      if (+v === 0) {
        str = '待处理'
      }
      if (+v === 1) {
        str = '已完成'
      }
      if (+v === -1) {
        str = '已驳回'
      }
      return str
    }
  },
  methods: {
    getList() {
      api.Store.getSellList().then(response => {
        let { data } = response
        data = base64.parse(data)
        this.list = data.list
      })
    },
    check(item) {
      this.$createDialog({
        type: 'confirm',
        title: '确定要通过审核吗?',
        onConfirm: () => {
          api.Store.sellCheck({ id: item.id}).then(() => {
            this.$set(item, 'status', 1)
          })
        },
        onCancel: () => {
        }
      }).show()
    },
    reject(item) {
      this.$createDialog({
        type: 'confirm',
        title: '确定要通过审核吗?',
        onConfirm: () => {
          api.Store.sellReject({ id: item.id}).then(() => {
            this.$set(item, 'status', -1)
          })
        },
        onCancel: () => {
        }
      }).show()
    }
  },
  created() {
    this.getList()
  }
}
</script>

<style scoped lang="stylus">
.wrapper
  .list
    text-align left
    .item
      padding 10px
      background white
      border-radius 5px
      margin-bottom 10px
      .time, .sum, .user
        height 20px
        line-height 20px
      .ops
        height 50px
        display flex
        align-items center
        div
          margin-right 10px
</style>
